home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Utilities / vim-5.1 / src / vim.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-03  |  25.8 KB  |  860 lines

  1. /* vi:set ts=8 sts=4 sw=4:
  2.  *
  3.  * VIM - Vi IMproved    by Bram Moolenaar
  4.  *
  5.  * Do ":help uganda"  in Vim to read copying and usage conditions.
  6.  * Do ":help credits" in Vim to see a list of people who contributed.
  7.  */
  8.  
  9. /* ============ the header file puzzle (ca. 50-100 pieces) ========= */
  10.  
  11. #ifdef HAVE_CONFIG_H    /* GNU autoconf (or something else) was here */
  12. # include "config.h"
  13. # define HAVE_PATHDEF
  14. #endif
  15.  
  16. #ifdef __EMX__        /* hand-edited config.h for OS/2 with EMX */
  17. # include "os_os2_cfg.h"
  18. #endif
  19.  
  20. /*
  21.  * This is a bit of a wishlist.  Currently we only have the Motif, Athena and
  22.  * Win32 GUIs.
  23.  */
  24. #if defined macintosh
  25. # define USE_GUI_MAC        /* mandatory */
  26. #endif
  27. #if defined(USE_GUI_MOTIF) \
  28.     || defined(USE_GUI_ATHENA) \
  29.     || defined(USE_GUI_MAC) \
  30.     || defined(USE_GUI_WIN16) \
  31.     || defined(USE_GUI_WIN32) \
  32.     || defined(USE_GUI_OS2) \
  33.     || defined(USE_GUI_BEOS)
  34. # ifndef USE_GUI
  35. #  define USE_GUI
  36. # endif
  37. #endif
  38.  
  39. /*
  40.  * NextStep has a problem with configure, undefine a few things:
  41.  */
  42. #ifdef NeXT
  43. # undef HAVE_UTIME
  44. # undef HAVE_SYS_UTSNAME_H
  45. #endif
  46.  
  47. #include "feature.h"    /* #defines for optionals and features */
  48.  
  49. /*
  50.  * Find out if function definitions should include argument types
  51.  */
  52. #ifdef AZTEC_C
  53. # include <functions.h>
  54. # define __ARGS(x)  x
  55. #endif
  56.  
  57. #ifdef SASC
  58. # include <clib/exec_protos.h>
  59. # define __ARGS(x)  x
  60. #endif
  61.  
  62. #ifdef _DCC
  63. # include <clib/exec_protos.h>
  64. # define __ARGS(x)  x
  65. #endif
  66.  
  67. #ifdef __TURBOC__
  68. # define __ARGS(x) x
  69. #endif
  70.  
  71. #ifdef __BEOS__
  72. # include "os_beos.h"
  73. # define __ARGS(x)  x
  74. #endif
  75.  
  76. #if defined(UNIX) || defined(__EMX__)
  77. # include "os_unix.h"        /* bring lots of system header files */
  78. #endif
  79.  
  80. #ifdef VMS
  81. # include "os_vms.h"
  82. #endif
  83.  
  84. #ifndef __ARGS
  85. # if defined(__STDC__) || defined(__GNUC__) || defined(WIN32)
  86. #  define __ARGS(x) x
  87. # else
  88. #  define __ARGS(x) ()
  89. # endif
  90. #endif
  91.  
  92. /* __ARGS and __PARMS are the same thing. */
  93. #ifndef __PARMS
  94. # define __PARMS(x) __ARGS(x)
  95. #endif
  96.  
  97. #ifdef UNIX
  98. # include "osdef.h"    /* bring missing declarations in */
  99. #endif
  100.  
  101. #ifdef __EMX__
  102. # define    getcwd  _getcwd2
  103. # define    chdir   _chdir2
  104. # undef        CHECK_INODE
  105. #endif
  106.  
  107. #ifdef AMIGA
  108. # include "os_amiga.h"
  109. #endif
  110.  
  111. #ifdef ARCHIE
  112. # include "os_archie.h"
  113. #endif
  114.  
  115. #ifdef MSDOS
  116. # include "os_msdos.h"
  117. #endif
  118.  
  119. #ifdef WIN32
  120. # include "os_win32.h"
  121. #endif
  122.  
  123. #ifdef __MINT__
  124. # include "os_mint.h"
  125. #endif
  126.  
  127. #ifdef macintosh
  128. # include "os_mac.h"
  129. #endif
  130.  
  131. /*
  132.  * Maximum length of a path (for non-unix systems) Make it a bit long, to stay
  133.  * on the safe side.  But not too long to put on the stack.
  134.  */
  135. #ifndef MAXPATHL
  136. # ifdef MAXPATHLEN
  137. #  define MAXPATHL  MAXPATHLEN
  138. # else
  139. #  define MAXPATHL  256
  140. # endif
  141. #endif
  142.  
  143. #define NUMBUFLEN 30        /* length of a buffer to store a number in ASCII */
  144.  
  145. /*
  146.  * Shorthand for unsigned variables. Many systems, but not all, have u_char
  147.  * already defined, so we use char_u to avoid trouble.
  148.  */
  149. typedef unsigned char    char_u;
  150. typedef unsigned short    short_u;
  151. typedef unsigned int    int_u;
  152. typedef unsigned long    long_u;
  153.  
  154. #ifndef UNIX            /* For Unix this is included in os_unix.h */
  155. #include <stdio.h>
  156. #include <ctype.h>
  157. #endif
  158.  
  159. #if defined(HAVE_STRING_H)
  160. # include <string.h>
  161. #else
  162. # ifdef HAVE_STRINGS_H
  163. #  include <strings.h>
  164. # endif
  165. #endif
  166.  
  167. #include "ascii.h"
  168. #include "keymap.h"
  169. #include "term.h"
  170. #include "macros.h"
  171.  
  172. #ifdef LATTICE
  173. # include <sys/types.h>
  174. # include <sys/stat.h>
  175. #endif
  176. #ifdef _DCC
  177. # include <sys/stat.h>
  178. #endif
  179. #if defined MSDOS  ||  defined WIN32
  180. # include <sys/stat.h>
  181. #endif
  182.  
  183. /* allow other (non-unix) systems to configure themselves now */
  184. #ifndef UNIX
  185. # ifdef HAVE_STAT_H
  186. #  include <stat.h>
  187. # endif
  188. # ifdef HAVE_STDLIB_H
  189. #  include <stdlib.h>
  190. # endif
  191. #endif /* NON-UNIX */
  192.  
  193. /* ================ end of the header file puzzle =============== */
  194.  
  195. /*
  196.  * flags for update_screen()
  197.  * The higher the value, the higher the priority
  198.  */
  199. #define VALID            10  /* buffer not changed */
  200. #define INVERTED        20  /* redisplay inverted part */
  201. #define VALID_TO_CURSCHAR    30  /* line at/below cursor changed */
  202. #define VALID_BEF_CURSCHAR    35  /* line just above cursor changed */
  203. #define NOT_VALID        40  /* buffer changed somewhere */
  204. #define CLEAR            50  /* screen messed up, clear it */
  205.  
  206. /*
  207.  * Hints used to optimize screen updating.
  208.  */
  209. #define HINT_NONE    0        /* no current hint */
  210. #define HINT_DEL_CHAR    1        /* delete character */
  211. #define HINT_INS_CHAR    2        /* insert character */
  212.  
  213. /*
  214.  * Terminal highlighting attribute bits.
  215.  * Attibutes above HL_ALL are used for syntax highlighting.
  216.  */
  217. #define HL_NORMAL        0x00
  218. #define HL_INVERSE        0x01
  219. #define HL_BOLD            0x02
  220. #define HL_ITALIC        0x04
  221. #define HL_UNDERLINE        0x08
  222. #define HL_STANDOUT        0x10
  223. #define HL_ALL            0x1f
  224.  
  225. /*
  226.  * values for State
  227.  *
  228.  * The lower byte is used to distinguish normal/visual/op_pending and cmdline/
  229.  * insert+replace mode.  This is used for mapping.  If none of these bits are
  230.  * set, no mapping is done.
  231.  * The upper byte is used to distinguish between other states.
  232.  */
  233. #define NORMAL        0x01    /* Normal mode, command expected */
  234. #define VISUAL        0x02    /* Visual mode */
  235. #define OP_PENDING    0x04    /* Normal mode, operator is pending */
  236. #define CMDLINE        0x08    /* Editing command line */
  237. #define INSERT        0x10    /* Insert mode */
  238.  
  239. #define NORMAL_BUSY    (0x100 + NORMAL) /* Normal mode, busy with a command */
  240. #define REPLACE        (0x200 + INSERT) /* Replace mode */
  241. #define HITRETURN    (0x600 + NORMAL) /* waiting for return or command */
  242. #define ASKMORE        0x700    /* Asking if you want --more-- */
  243. #define SETWSIZE    0x800    /* window size has changed */
  244. #define ABBREV        0x900    /* abbreviation instead of mapping */
  245. #define EXTERNCMD    0xa00    /* executing an external command */
  246. #define SHOWMATCH    (0xb00 + INSERT) /* show matching paren */
  247.  
  248. /* directions */
  249. #define FORWARD            1
  250. #define BACKWARD        (-1)
  251. #define BOTH_DIRECTIONS        2
  252.  
  253. /* return values for functions */
  254. #define OK            1
  255. #define FAIL            0
  256.  
  257. /* flags for b_flags */
  258. #define BF_RECOVERED        1   /* buffer has been recovered */
  259. #define BF_CHECK_RO        2   /* need to check readonly when loading
  260.                        file into buffer (set by ":e", may be
  261.                        reset by ":buf" */
  262. #define BF_NEVERLOADED        4   /* file has never been loaded into buffer,
  263.                        many variables still need to be set */
  264.  
  265. /*
  266.  * values for command line completion
  267.  */
  268. #define CONTEXT_UNKNOWN        (-2)
  269. #define EXPAND_UNSUCCESSFUL    (-1)
  270. #define EXPAND_NOTHING        0
  271. #define EXPAND_COMMANDS        1
  272. #define EXPAND_FILES        2
  273. #define EXPAND_DIRECTORIES    3
  274. #define EXPAND_SETTINGS        4
  275. #define EXPAND_BOOL_SETTINGS    5
  276. #define EXPAND_TAGS        6
  277. #define EXPAND_OLD_SETTING    7
  278. #define EXPAND_HELP        8
  279. #define EXPAND_BUFFERS        9
  280. #define EXPAND_EVENTS        10
  281. #define EXPAND_MENUS        11
  282. #define EXPAND_SYNTAX        12
  283. #define EXPAND_HIGHLIGHT    13
  284. #define EXPAND_AUGROUP        14
  285.  
  286. /* Values for nextwild() and ExpandOne().  See ExpandOne() for meaning. */
  287. #define WILD_FREE        1
  288. #define WILD_EXPAND_FREE    2
  289. #define WILD_EXPAND_KEEP    3
  290. #define WILD_NEXT        4
  291. #define WILD_PREV        5
  292. #define WILD_ALL        6
  293. #define WILD_LONGEST        7
  294.  
  295. #define WILD_LIST_NOTFOUND    1
  296. #define WILD_HOME_REPLACE    2
  297. #define WILD_USE_NL        4    /* separate names with '\n' */
  298.  
  299. /* Flags for expand_wildcards() */
  300. #define EW_DIR        1    /* include directory names */
  301. #define EW_FILE        2    /* include file names */
  302. #define EW_NOTFOUND    4    /* include not found names */
  303. #ifdef NO_EXPANDPATH
  304. # define expand_wildcards mch_expand_wildcards
  305. #endif
  306.  
  307. /* Values for the find_pattern_in_path() function args 'type' and 'action': */
  308. #define FIND_ANY    1
  309. #define FIND_DEFINE    2
  310. #define CHECK_PATH    3
  311.  
  312. #define ACTION_SHOW    1
  313. #define ACTION_GOTO    2
  314. #define ACTION_SPLIT    3
  315. #define ACTION_SHOW_ALL    4
  316. #ifdef INSERT_EXPAND
  317. # define ACTION_EXPAND    5
  318. #endif
  319.  
  320. /* Values for 'options' argument in do_search() and searchit() */
  321. #define SEARCH_REV    0x01  /* go in reverse of previous dir. */
  322. #define SEARCH_ECHO   0x02  /* echo the search command and handle options */
  323. #define SEARCH_MSG    0x0c  /* give messages (yes, it's not 0x04) */
  324. #define SEARCH_NFMSG  0x08  /* give all messages except not found */
  325. #define SEARCH_OPT    0x10  /* interpret optional flags */
  326. #define SEARCH_HIS    0x20  /* put search pattern in history */
  327. #define SEARCH_END    0x40  /* put cursor at end of match */
  328. #define SEARCH_NOOF   0x80  /* don't add offset to position */
  329. #define SEARCH_START 0x100  /* start search without col offset */
  330. #define SEARCH_MARK  0x200  /* set previous context mark */
  331. #define SEARCH_KEEP  0x400  /* keep previous search pattern */
  332.  
  333. /* Values for find_ident_under_cursor() */
  334. #define FIND_IDENT    1    /* find identifier (word) */
  335. #define FIND_STRING    2    /* find any string (WORD) */
  336.  
  337. /* Values for get_file_name_in_path() */
  338. #define FNAME_MESS    1    /* give error message */
  339. #define FNAME_EXP    2    /* expand to path */
  340. #define FNAME_HYP    4    /* check for hypertext link */
  341.  
  342. /* Values for buflist_getfile() */
  343. #define GETF_SETMARK    0x01    /* set pcmark before jumping */
  344. #define GETF_ALT    0x02    /* jumping to alternate file (not buf num) */
  345.  
  346. /* Values for in_indentkeys() */
  347. #define KEY_OPEN_FORW    0x101
  348. #define KEY_OPEN_BACK    0x102
  349.  
  350. /* Values for mch_call_shell() second argument */
  351. #define SHELL_FILTER    1    /* filtering text */
  352. #define SHELL_EXPAND    2    /* expanding wildcards */
  353. #define SHELL_COOKED    4    /* set term to cooked mode */
  354. #define SHELL_DOOUT    8    /* redirecting output */
  355.  
  356. /* Values for readfile() flags */
  357. #define READ_NEW    0x01    /* read a file into a new buffer */
  358. #define READ_FILTER    0x02    /* read filter output */
  359. #define READ_STDIN    0x04    /* read from stdin */
  360.  
  361. /* Values for change_indent() */
  362. #define INDENT_SET    1    /* set indent */
  363. #define INDENT_INC    2    /* increase indent */
  364. #define INDENT_DEC    3    /* decrease indent */
  365.  
  366. /* Values for flags argument for findmatchlimit() */
  367. #define FM_BACKWARD    0x01    /* search backwards */
  368. #define FM_FORWARD    0x02    /* search forwards */
  369. #define FM_BLOCKSTOP    0x04    /* stop at start/end of block */
  370. #define FM_SKIPCOMM    0x08    /* skip comments */
  371.  
  372. /* Values for action argument for do_buffer() */
  373. #define DOBUF_GOTO    0    /* go to specified buffer */
  374. #define DOBUF_SPLIT    1    /* split window and go to specified buffer */
  375. #define DOBUF_UNLOAD    2    /* unload specified buffer(s) */
  376. #define DOBUF_DEL    3    /* delete specified buffer(s) */
  377.  
  378. /* Values for start argument for do_buffer() */
  379. #define DOBUF_CURRENT    0    /* "count" buffer from current buffer */
  380. #define DOBUF_FIRST    1    /* "count" buffer from first buffer */
  381. #define DOBUF_LAST    2    /* "count" buffer from last buffer */
  382. #define DOBUF_MOD    3    /* "count" mod. buffer from current buffer */
  383.  
  384. /* Values for sub_cmd and which_pat argument for search_regcomp() */
  385. /* Also used for which_pat argument for searchit() */
  386. #define RE_SEARCH   0        /* save/use pat in/from search_pattern */
  387. #define RE_SUBST    1        /* save/use pat in/from subst_pattern */
  388. #define RE_BOTH        2        /* save pat in both patterns */
  389. #define RE_LAST        2        /* use last used pattern if "pat" is NULL */
  390.  
  391. /* Return values for fullpathcmp() */
  392. /* Note: can use (fullpathcmp() & FPC_SAME) to check for equal files */
  393. #define FPC_SAME   1        /* both exist and are the same file. */
  394. #define FPC_DIFF   2        /* both exist and are different files. */
  395. #define FPC_NOTX   4        /* both don't exist. */
  396. #define FPC_DIFFX  6        /* one of them doesn't exist. */
  397. #define FPC_SAMEX  7        /* both don't exist and file names are same. */
  398.  
  399. /* flags for do_ecmd() */
  400. #define ECMD_HIDE    0x01    /* don't free the current buffer */
  401. #define ECMD_SET_HELP    0x02    /* set b_help flag of (new) buffer before
  402.                    opening file */
  403. #define ECMD_OLDBUF    0x04    /* use existing buffer if it exists */
  404. #define ECMD_FORCEIT    0x08    /* ! used in Ex command */
  405.  
  406. /* flags for do_cmdline() */
  407. #define DOCMD_VERBOSE 0x01  /* included command in error message */
  408. #define DOCMD_NOWAIT  0x02  /* don't call wait_return() and friends */
  409. #define DOCMD_REPEAT  0x04  /* repeat execution until getline() returns NULL */
  410.  
  411. /* flags for beginline() */
  412. #define BL_WHITE    1        /* cursor on first non-white in the line */
  413. #define BL_SOL        2        /* use 'sol' option */
  414. #define BL_FIX        4        /* don't leave cursor on a NUL */
  415.  
  416. /* flags for mf_sync() */
  417. #define MFS_ALL        1        /* also sync blocks with negative numbers */
  418. #define MFS_STOP    2        /* stop syncing when a character is available */
  419. #define MFS_FLUSH   4        /* flushed file to disk */
  420. #define MFS_ZERO    8        /* only write block 0 */
  421.  
  422. /* flags for buf_copy_options() */
  423. #define BCO_ENTER   1        /* going to enter the buffer */
  424. #define BCO_ALWAYS  2        /* always copy the options */
  425. #define BCO_NOHELP  4        /* don't touch the help related options */
  426.  
  427. /*
  428.  * There are three history tables:
  429.  */
  430. #define HIST_CMD    0        /* colon commands */
  431. #define HIST_SEARCH 1        /* search commands */
  432. #define HIST_EXPR   2        /* expressions (from entering | register) */
  433. #define HIST_COUNT  3        /* number of history tables */
  434.  
  435. /*
  436.  * Flags for chartab[].
  437.  */
  438. #define CHAR_MASK    0x03    /* low two bits for size */
  439. #define CHAR_IP        0x04    /* third bit set for printable chars */
  440. #define CHAR_ID        0x08    /* fourth bit set for ID chars */
  441. #define CHAR_IF        0x10    /* fifth bit set for file name chars */
  442.  
  443. /*
  444.  * Values for do_tag().
  445.  */
  446. #define DT_TAG        1    /* jump to newer position or same tag again */
  447. #define DT_POP        2    /* jump to older position */
  448. #define DT_NEXT        3    /* jump to next match of same tag */
  449. #define DT_PREV        4    /* jump to previous match of same tag */
  450. #define DT_FIRST    5    /* jump to first match of same tag */
  451. #define DT_LAST        6    /* jump to first match of same tag */
  452. #define DT_SELECT    7    /* jump to selection from list */
  453. #define DT_HELP        8    /* like DT_TAG, but no wildcards */
  454. #define DT_JUMP        9    /* jump to new tag or selection from list */
  455.  
  456. /*
  457.  * flags for find_tags().
  458.  */
  459. #define TAG_HELP    1    /* only search for help tags */
  460. #define TAG_NAMES    2    /* only return name of tag */
  461. #define    TAG_REGEXP    4    /* use tag pattern as regexp */
  462. #define    TAG_NOIC    8    /* don't always ignore case */
  463.  
  464. /*
  465.  * Events for autocommands.
  466.  */
  467. enum auto_event
  468. {
  469.     EVENT_BUFDELETE = 0,    /* just before deleting a buffer */
  470.     EVENT_BUFENTER,        /* after entering a buffer */
  471.     EVENT_BUFLEAVE,        /* before leaving a buffer */
  472.     EVENT_BUFNEWFILE,        /* when creating a buffer for a new file */
  473.     EVENT_BUFREADPOST,        /* after reading a buffer */
  474.     EVENT_BUFREADPRE,        /* before reading a buffer */
  475.     EVENT_BUFUNLOAD,        /* just before unloading a buffer */
  476.     EVENT_BUFWRITEPOST,        /* after writing a buffer */
  477.     EVENT_BUFWRITEPRE,        /* before writing a buffer */
  478.     EVENT_FILEAPPENDPOST,   /* after appending to a file */
  479.     EVENT_FILEAPPENDPRE,    /* before appending to a file */
  480.     EVENT_FILECHANGEDSHELL, /* after shell command that changed file */
  481.     EVENT_FILEREADPOST,        /* after reading a file */
  482.     EVENT_FILEREADPRE,        /* before reading a file */
  483.     EVENT_FILEWRITEPOST,    /* after writing a file */
  484.     EVENT_FILEWRITEPRE,        /* before writing a file */
  485.     EVENT_FILTERREADPOST,   /* after reading from a filter */
  486.     EVENT_FILTERREADPRE,    /* before reading from a filter */
  487.     EVENT_FILTERWRITEPOST,  /* after writing to a filter */
  488.     EVENT_FILTERWRITEPRE,   /* before writing to a filter */
  489.     EVENT_STDINREADPOST,    /* after reading from stdin */
  490.     EVENT_STDINREADPRE,        /* before reading from stdin */
  491.     EVENT_TERMCHANGED,        /* after changing 'term' */
  492.     EVENT_USER,            /* user defined autocommand */
  493.     EVENT_VIMENTER,        /* after starting Vim */
  494.     EVENT_VIMLEAVE,        /* before exiting Vim */
  495.     EVENT_WINENTER,        /* after entering a window */
  496.     EVENT_WINLEAVE,        /* before leaving a window */
  497.     NUM_EVENTS            /* MUST be the last one */
  498. };
  499.  
  500. typedef enum auto_event EVENT_T;
  501.  
  502. /*
  503.  * Values for index in highlight_attr[].
  504.  * When making changes, also update the table in highlight_changed()!
  505.  */
  506. enum hlf_value
  507. {
  508.     HLF_8 = 0,        /* Meta & special keys listed with ":map" */
  509.     HLF_AT,        /* @ and ~ characters at end of screen */
  510.     HLF_D,        /* directories in CTRL-D listing */
  511.     HLF_E,        /* error messages */
  512.     HLF_H,        /* obsolete, ignored */
  513.     HLF_I,        /* incremental search */
  514.     HLF_L,        /* last search string */
  515.     HLF_M,        /* "--More--" message */
  516.     HLF_CM,        /* Mode (e.g., "-- INSERT --") */
  517.     HLF_N,        /* line number for ":number" and ":#" commands */
  518.     HLF_R,        /* return to continue message and yes/no questions */
  519.     HLF_S,        /* status lines */
  520.     HLF_SNC,        /* status lines of not-current windows */
  521.     HLF_T,        /* Titles for output from ":set all", ":autocmd" etc. */
  522.     HLF_V,        /* Visual mode */
  523.     HLF_W,        /* warning messages */
  524.     HLF_COUNT        /* MUST be the last one */
  525. };
  526.  
  527. /*
  528.  * Boolean constants
  529.  */
  530. #ifndef TRUE
  531. # define FALSE    0        /* note: this is an int, not a long! */
  532. # define TRUE    1
  533. #endif
  534.  
  535. #define MAYBE    2        /* sometimes used for a variant on TRUE */
  536.  
  537. /* May be returned by add_new_completion(): */
  538. #define RET_ERROR        (-1)
  539.  
  540. /*
  541.  * Operator IDs; The order must correspond to op_chars[] in normal.c!
  542.  */
  543. #define OP_NOP        0        /* no pending operation */
  544. #define OP_DELETE   1        /* delete operator */
  545. #define OP_YANK        2        /* yank operator */
  546. #define OP_CHANGE   3        /* change operator */
  547. #define OP_LSHIFT   4        /* left shift operator */
  548. #define OP_RSHIFT   5        /* right shift operator */
  549. #define OP_FILTER   6        /* filter operator */
  550. #define OP_TILDE    7        /* switch case operator */
  551. #define OP_INDENT   8        /* indent operator */
  552. #define OP_FORMAT   9        /* format operator */
  553. #define OP_COLON    10        /* colon operator */
  554. #define OP_UPPER    11        /* make upper case operator */
  555. #define OP_LOWER    12        /* make lower case operator */
  556. #define DO_JOIN        13        /* join operator, only for visual mode */
  557. #define OP_GFORMAT  14        /* "gq" operator */
  558.  
  559. /*
  560.  * Motion types, used for operators and for yank/delete registers.
  561.  */
  562. #define MCHAR    0        /* character-wise movement/register */
  563. #define MLINE    1        /* line-wise movement/register */
  564. #define MBLOCK    2        /* block-wise register */
  565.  
  566. /*
  567.  * Minimum screen size
  568.  */
  569. #define MIN_COLUMNS    12    /* minimal columns for screen */
  570. #define MIN_ROWS    1    /* minimal rows for one window */
  571. #define STATUS_HEIGHT    1    /* height of a status line under a window */
  572.  
  573. /*
  574.  * Buffer sizes
  575.  */
  576. #ifndef CMDBUFFSIZE
  577. # define CMDBUFFSIZE    256    /* size of the command processing buffer */
  578. #endif
  579.  
  580. #define LSIZE        512        /* max. size of a line in the tags file */
  581.  
  582. #define IOSIZE       (1024+1)    /* file i/o and sprintf buffer size */
  583. #define MSG_BUF_LEN 80        /* length of buffer for small messages */
  584.  
  585. #if defined(AMIGA) || defined(__linux__) || defined(__QNX__) || defined(__CYGWIN32__) || defined(_AIX)
  586. # define TBUFSZ 2048        /* buffer size for termcap entry */
  587. #else
  588. # define TBUFSZ 1024        /* buffer size for termcap entry */
  589. #endif
  590.  
  591. /*
  592.  * Maximum length of key sequence to be mapped.
  593.  * Must be able to hold an Amiga resize report.
  594.  */
  595. #define MAXMAPLEN   50
  596.  
  597. #ifdef BINARY_FILE_IO
  598. # define WRITEBIN   "wb"    /* no CR-LF translation */
  599. # define READBIN    "rb"
  600. # define APPENDBIN  "ab"
  601. #else
  602. # define WRITEBIN   "w"
  603. # define READBIN    "r"
  604. # define APPENDBIN  "a"
  605. #endif
  606.  
  607. /*
  608.  * EMX doesn't have a global way of making open() use binary I/O.
  609.  * Use O_BINARY for all open() calls.
  610.  */
  611. #if defined(__EMX__) || defined(__CYGWIN32__)
  612. # define O_EXTRA    O_BINARY
  613. #else
  614. # define O_EXTRA    0
  615. #endif
  616.  
  617. #define CHANGED        set_Changed()
  618. #define UNCHANGED(buf)    unset_Changed(buf)
  619.  
  620. /*
  621.  * defines to avoid typecasts from (char_u *) to (char *) and back
  622.  * (vim_strchr() and vim_strrchr() are now in alloc.c)
  623.  */
  624. #define STRLEN(s)        strlen((char *)(s))
  625. #define STRCPY(d, s)        strcpy((char *)(d), (char *)(s))
  626. #define STRNCPY(d, s, n)    strncpy((char *)(d), (char *)(s), (size_t)(n))
  627. #define STRCMP(d, s)        strcmp((char *)(d), (char *)(s))
  628. #define STRNCMP(d, s, n)    strncmp((char *)(d), (char *)(s), (size_t)(n))
  629. #ifdef HAVE_STRCASECMP
  630. # define STRICMP(d, s)        strcasecmp((char *)(d), (char *)(s))
  631. #else
  632. # ifdef HAVE_STRICMP
  633. #  define STRICMP(d, s)        stricmp((char *)(d), (char *)(s))
  634. # else
  635. #  define STRICMP(d, s)        vim_stricmp((char *)(d), (char *)(s))
  636. # endif
  637. #endif
  638. #ifdef HAVE_STRNCASECMP
  639. # define STRNICMP(d, s, n)  strncasecmp((char *)(d), (char *)(s), (size_t)(n))
  640. #else
  641. # ifdef HAVE_STRNICMP
  642. #  define STRNICMP(d, s, n) strnicmp((char *)(d), (char *)(s), (size_t)(n))
  643. # else
  644. #  define STRNICMP(d, s, n) vim_strnicmp((char *)(d), (char *)(s), (size_t)(n))
  645. # endif
  646. #endif
  647. #define STRCAT(d, s)        strcat((char *)(d), (char *)(s))
  648. #define STRNCAT(d, s, n)    strncat((char *)(d), (char *)(s), (size_t)(n))
  649.  
  650. #ifdef HAVE_STRPBRK
  651. # define vim_strpbrk(s, cs) (char_u *)strpbrk((char *)(s), (char *)(cs))
  652. #endif
  653.  
  654. #define MSG(s)            msg((char_u *)(s))
  655. #define MSG_ATTR(s, attr)   msg_attr((char_u *)(s), attr)
  656. #define EMSG(s)            emsg((char_u *)(s))
  657. #define EMSG2(s, p)        emsg2((char_u *)(s), (char_u *)(p))
  658. #define EMSGN(s, n)        emsgn((char_u *)(s), (long)(n))
  659. #define OUT_STR(s)        out_str((char_u *)(s))
  660. #define OUT_STR_NF(s)        out_str_nf((char_u *)(s))
  661. #define MSG_PUTS(s)        msg_puts((char_u *)(s))
  662. #define MSG_PUTS_ATTR(s, a) msg_puts_attr((char_u *)(s), a)
  663. #define MSG_PUTS_TITLE(s)   msg_puts_title((char_u *)(s))
  664.  
  665. typedef long        linenr_t;        /* line number type */
  666. typedef unsigned    colnr_t;        /* column number type */
  667.  
  668. #define MAXLNUM (0x7fffffff)        /* maximum (invalid) line number */
  669.  
  670. #if SIZEOF_INT >= 4
  671. # define MAXCOL    (0x7fffffff)        /* maximum column number, 31 bits */
  672. #else
  673. # define MAXCOL    (0x7fff)        /* maximum column number, 15 bits */
  674. #endif
  675.  
  676. #define SHOWCMD_COLS 10            /* columns needed by shown command */
  677.  
  678. /*
  679.  * Include a prototype for vim_memmove(), it may not be in alloc.pro.
  680.  */
  681. #ifdef VIM_MEMMOVE
  682. void vim_memmove __ARGS((void *, void *, size_t));
  683. #else
  684. # ifndef vim_memmove
  685. #  define vim_memmove(to, from, len) memmove(to, from, len)
  686. # endif
  687. #endif
  688.  
  689. /*
  690.  * For the Amiga we use a version of getenv that does local variables under 2.0
  691.  * For Win32 and MSDOS we also check $HOME when $VIM is used.
  692.  */
  693. #if !defined(AMIGA) && !defined(WIN32) && !defined(MSDOS) && !defined(VMS)
  694. # define vim_getenv(x) (char_u *)getenv((char *)x)
  695. #endif
  696.  
  697. /*
  698.  * fnamecmp() is used to compare file names.
  699.  * On some systems case in a file name does not matter, on others it does.
  700.  * (this does not account for maximum name lengths and things like "../dir",
  701.  * thus it is not 100% accurate!)
  702.  */
  703. #ifdef CASE_INSENSITIVE_FILENAME
  704. # define fnamecmp(x, y) STRICMP((x), (y))
  705. # define fnamencmp(x, y, n) STRNICMP((x), (y), (n))
  706. #else
  707. # define fnamecmp(x, y) strcmp((char *)(x), (char *)(y))
  708. # define fnamencmp(x, y, n) strncmp((char *)(x), (char *)(y), (size_t)(n))
  709. #endif
  710.  
  711. #ifdef HAVE_MEMSET
  712. # define vim_memset(ptr, c, size)   memset((ptr), (c), (size))
  713. #else
  714. void *vim_memset __ARGS((void *, int, size_t));
  715. #endif
  716.  
  717. #ifdef HAVE_MEMCMP
  718. # define vim_memcmp(p1, p2, len)   memcmp((p1), (p2), (len))
  719. #else
  720. # ifdef HAVE_BCMP
  721. #  define vim_memcmp(p1, p2, len)   bcmp((p1), (p2), (len))
  722. # else
  723. int vim_memcmp __ARGS((void *, void *, size_t));
  724. #  define VIM_MEMCMP
  725. # endif
  726. #endif
  727.  
  728. /* for MS-DOS and Win32: use chdir() that also changes the default drive */
  729. #ifdef USE_VIM_CHDIR
  730. int vim_chdir __ARGS((char *));
  731. #else
  732. # define vim_chdir chdir
  733. #endif
  734.  
  735. /*
  736.  * vim_iswhite() is used for "^" and the like. It differs from isspace()
  737.  * because it doesn't include <CR> and <LF> and the like.
  738.  */
  739. #define vim_iswhite(x)    ((x) == ' ' || (x) == '\t')
  740.  
  741. /* Note that gui.h is included by structs.h */
  742.  
  743. #include "regexp.h"        /* for struct regexp */
  744. #include "structs.h"        /* file that defines many structures */
  745.  
  746. #ifdef USE_MOUSE
  747.  
  748. /* Codes for mouse event */
  749. #define MOUSE_LEFT    0x00
  750. #define MOUSE_MIDDLE    0x01
  751. #define MOUSE_RIGHT    0x02
  752. #define MOUSE_RELEASE    0x03
  753. #define MOUSE_SHIFT    0x04
  754. #define MOUSE_ALT    0x08
  755. #define MOUSE_CTRL    0x10
  756.  
  757. /* 0x20 is reserved by xterm */
  758.  
  759. #define MOUSE_DRAG    (0x40 | MOUSE_RELEASE)
  760.  
  761. #define MOUSE_CLICK_MASK    0x03
  762.  
  763. #define NUM_MOUSE_CLICKS(code) \
  764.     (((unsigned)((code) & 0xC0) >> 6) + 1)
  765.  
  766. #define SET_NUM_MOUSE_CLICKS(code, num) \
  767.     (code) = ((code) & 0x3f) | ((((num) - 1) & 3) << 6)
  768.  
  769. /*
  770.  * jump_to_mouse() returns one of these values, possibly with
  771.  * CURSOR_MOVED added
  772.  */
  773. #define IN_UNKNOWN    1
  774. #define IN_BUFFER    2
  775. #define IN_STATUS_LINE    3        /* Or in command line */
  776. #define CURSOR_MOVED    0x100
  777.  
  778. /* flags for jump_to_mouse() */
  779. #define MOUSE_FOCUS        0x01    /* need to stay in this window */
  780. #define MOUSE_MAY_VIS        0x02    /* may start Visual mode */
  781. #define MOUSE_DID_MOVE        0x04    /* only act when mouse has moved */
  782. #define MOUSE_SETPOS        0x08    /* only set current mouse position */
  783. #define MOUSE_MAY_STOP_VIS    0x10    /* may stop Visual mode */
  784.  
  785. #endif /* USE_MOUSE */
  786.  
  787. #ifdef USE_CLIPBOARD
  788.  
  789. /* Selection states for selection that doesn't use Visual mode */
  790. #define SELECT_CLEARED        0
  791. #define SELECT_IN_PROGRESS    1
  792. #define SELECT_DONE        2
  793.  
  794. #define SELECT_MODE_CHAR    0
  795. #define SELECT_MODE_WORD    1
  796. #define SELECT_MODE_LINE    2
  797.  
  798. #ifdef USE_GUI_WIN32
  799. # ifdef HAVE_OLE
  800. #  define WM_OLE (WM_APP+0)
  801. # endif
  802. #endif
  803.  
  804. /* Info about selected text */
  805. typedef struct VimClipboard
  806. {
  807.     int        available;        /* Is clipboard available? */
  808.     int        owned;            /* Flag: do we own the selection? */
  809.     FPOS    start;            /* Start of selected area */
  810.     FPOS    end;            /* End of selected area */
  811.     int        vmode;            /* Visual mode character */
  812.  
  813.     /* Fields for selection that doesn't use Visual mode */
  814.     short_u    origin_row;
  815.     short_u    origin_start_col;
  816.     short_u    origin_end_col;
  817.     short_u    word_start_col;
  818.     short_u    word_end_col;
  819.  
  820.     FPOS    prev;            /* Previous position */
  821.     short_u    state;            /* Current selection state */
  822.     short_u    mode;            /* Select by char, word, or line. */
  823.  
  824. #ifdef USE_GUI_X11
  825.     Atom    atom;            /* Vim's own special selection format */
  826. #endif
  827. #ifdef WIN32
  828.     int_u    format;            /* Vim's own special clipboard format */
  829. #endif
  830. #ifdef USE_GUI_BEOS
  831.                     /* no clipboard at the moment */
  832. #endif
  833. } VimClipboard;
  834. #endif /* USE_CLIPBOARD */
  835.  
  836. #ifdef __BORLANDC__
  837. /* work around a bug in the Borland 'stat' function: */
  838. #include <io.h>        /* for access() */
  839.  
  840. #define stat(a,b) (access(a,0) ? -1 : stat(a,b))
  841. #endif
  842.  
  843. #include "globals.h"        /* global variables and messages */
  844. #include "option.h"        /* option variables and defines */
  845. #include "ex_cmds.h"        /* Ex command defines */
  846. #include "proto.h"        /* function prototypes */
  847.  
  848. #ifdef USE_SNIFF
  849. # include "if_sniff.h"
  850. #endif
  851.  
  852. /* This has to go after the include of proto.h, as proto/os_win32.pro declares
  853.  * functions of these names. The declarations would break if the defines had
  854.  * been seen at that stage.
  855.  */
  856. #if !defined(USE_GUI_WIN32) && !defined(macintosh)
  857. # define mch_errmsg(str)    fprintf(stderr, (str))
  858. # define mch_display_error()    fflush(stderr)
  859. #endif
  860.